Add environment variable support for automation#8515
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for authenticating the extension to GitHub.com using an environment-provided token, intended to enable non-interactive/automation scenarios without relying on VS Code’s authentication session.
Changes:
- Introduces
tryInitializeFromEnvironmentToken()to create a GitHub client fromprocess.env.GITHUB_OAUTH_TOKEN. - Hooks env-token initialization into the start of
initialize()so it takes precedence over VS Code auth sessions.
Comments suppressed due to low confidence (3)
src/github/credentials.ts:171
- New auth behavior (env-token initialization + precedence over VS Code auth) is not covered by tests. Since this impacts core authentication and session/scopes upgrade flows, add unit tests to cover at least: env token present/absent, env token ignored when forcing a new session, and required-scope upgrade interactions.
const envResult = await this.tryInitializeFromEnvironmentToken(authProviderId);
if (envResult) {
return envResult;
}
src/github/credentials.ts:171
initialize()now attempts env-token auth unconditionally, which means explicit interactive flows (e.g.forceNewSession,createIfNone: true) can no longer force a VS Code authentication session. This can prevent users from switching accounts or re-consenting scopes unless they manually unset the env var. Consider only using the env token whengetAuthSessionOptions.silentis true (or when neitherforceNewSessionnorcreateIfNoneis set), or add an explicit opt-out flag for env-token auth.
const envResult = await this.tryInitializeFromEnvironmentToken(authProviderId);
if (envResult) {
return envResult;
}
src/github/credentials.ts:171
- Env-token initialization bypasses the
scopes/requireScopeslogic used for upgrading sessions (e.g.getHubEnsureAdditionalScopes()callsinitialize(..., SCOPES_WITH_ADDITIONAL, true)). With the current early-return, the code will report success without ensuring/recording the requested scopes, which can cause repeated upgrade attempts or later authorization failures. Consider plumbingscopes/requireScopesintotryInitializeFromEnvironmentTokenand either (a) validate the token has the needed scopes or (b) explicitly set the store’s effective scopes to the requested set when env auth is used.
const envResult = await this.tryInitializeFromEnvironmentToken(authProviderId);
if (envResult) {
return envResult;
}
jrieken
approved these changes
Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.